package com.chenliang.controller;

import com.chenliang.domain.Permission;
import com.chenliang.service.IPermissionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @ProjectName: mavenSSM
 * @Package: com.chenliang.controller
 * 作用：
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService service;

    @RequestMapping("/findAll")
    public String findAll(Model model,
      @RequestParam(name = "page", defaultValue = "1", required = true) Integer page,
      @RequestParam(name = "pageSize", defaultValue = "3", required = true) Integer pageSize) {

        List<Permission> permissions = service.findAll(page, pageSize);
        PageInfo pageInfo=new PageInfo(permissions);
        model.addAttribute("pageInfo",pageInfo);
        return "permission-list";
    }

    @RequestMapping("/findById")
    public String findById(Model model,String id){
       Permission permission= service.findById(id);
        model.addAttribute("permission",permission);
        return "permission-show";
    }

@RequestMapping("/permissionAdd")
    public String permissionAdd(Permission permission){
        service.permissionAdd(permission);
        return "redirect:/permission/findAll";
    }
    @RequestMapping("/findByIdPermission")
    public String findByIdPermission(Model model,String id){
         Permission permission= service.findByIdPermission(id);
        model.addAttribute("Permission",permission);
        System.out.println(permission);
        return "permission-show";
    }
}
